package com.huika.renrench.control.welcome;

import android.content.Intent;
import android.support.v4.view.CustomViewPager;
import android.support.v4.view.CustomViewPager.OnRightEndScrollListener;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;

import com.huika.renrench.R;
import com.huika.renrench.control.common.base.BaseAct;
import com.huika.renrench.control.main.activity.MainActivity;

/**
 * 引导页面（第一次进入时开启）
 * @description：
 * @author ldm
 * @date 2014年12月2日 上午9:25:21
 */
public class GuideViewAct extends BaseAct implements OnRightEndScrollListener {
	private CustomViewPager mViewPager;

	public GuideViewAct() {
		setAllowFullScreen(true);
		setHiddenActionBar(true);
	}

	@Override
	public void setRootView() {
		setContentView(R.layout.layout_guide_view);
	}

	@Override
	protected void initWidget() {
		super.initWidget();
		mViewPager = (CustomViewPager) findViewById(R.id.whatsnew_viewpager);
		mViewPager.setRightEndScrollListener(this);
		PagerAdapter mPagerAdapter = new PagerAdapter() {

			@Override
			public boolean isViewFromObject(View arg0, Object arg1) {
				return arg0 == arg1;
			}

			@Override
			public int getCount() {
				return 4;
			}

			@Override
			public void destroyItem(View container, int position, Object object) {
				((ViewPager) container).removeView((View) object);
			}

			@Override
			public View instantiateItem(View container, int position) {
				LayoutInflater inflater = LayoutInflater.from(container.getContext());
				int layoutId = getResources().getIdentifier("view_guide_" + (position + 1), "layout", getPackageName());
				View pView = inflater.inflate(layoutId, (ViewPager) container, false);
				((ViewPager) container).addView(pView);
				return pView;
			}
		};

		mViewPager.setAdapter(mPagerAdapter);
	}

	@Override
	public void widgetClick(View v) {
		super.widgetClick(v);
	}

	/**
	 * 最后一张图片Viewpager上面的开始按钮
	 * 
	 * @param v
	 */
	public void startbutton(View v) {
		System.gc();
		Intent intent = new Intent();
//		intent.setClass(GuideViewAct.this, LoginActivity.class);
		intent.setClass(GuideViewAct.this, MainActivity.class);//确认跳转到主页面
		startActivity(intent);
		this.finish();
	}

	@Override
	public void onRightEndScrollListener() {
		startbutton(null);
	}



}
